orgStr = '恭喜<color=#144db6>安定依白</color>的贵族等级达到VIP<color=#ffffff>贵族5</color>，获得多项专属特权，羡煞旁人！';
--orgStr = '安定依白:哈哈□6□多试□7□水电<color=#ff0000>你好1</color>撒<color=#ff0000>你好2</color>地是的';
--orgStr = '安定依白:哈哈□6□多试□7□水电地是的';
str = orgStr;



--[[
截取字符串
]]--
-- 判断utf8字符byte长度
function chsize( char )
    if not char then
        --print("not char")
        return 0
    elseif char > 240 then
        return 4
    elseif char > 225 then
        return 3
    elseif char > 192 then
        return 2
    else
        return 1
    end
end

--获取utf8的字符长度
function utf8len(str)  
    local len = 0
    local currentIndex = 1
    while currentIndex <= #str do
        local char = string.byte(str, currentIndex)
        currentIndex = currentIndex + chsize(char)
        len = len +1
    end
    return len
end 

--截取字符串
-- str:         要截取的字符串
-- startChar:   开始字符下标,从1开始
-- numChars:    要截取的字符长度
function utf8sub( str, startChar, numChars )
	local startIndex = 1
    while startChar > 1 do
        local char = string.byte(str, startIndex)
        startIndex = startIndex + chsize(char)
        startChar = startChar - 1
    end

    local currentIndex = startIndex

    while numChars > 0 and currentIndex <= #str do
        local char = string.byte(str, currentIndex)
        currentIndex = currentIndex + chsize(char)
        numChars = numChars -1
    end
    return str:sub(startIndex, currentIndex - 1)
end

function split(s,delim)
	
    if type(delim) ~= "string" or string.len(delim) <= 0 then
      return
    end

    local start = 1
    local t = {}
    while true do
        local pos,endPos,value = string.find (s, delim, start) -- plain find
        if not pos then
           break
        end
   
        table.insert (t, string.sub (s, start, pos-1 ))
        table.insert (t, value)

        start = pos + string.len(value)
    end
    table.insert (t, string.sub (s, start))
   
return t

end

function formatInfos(str,parttern,isFace)
    local stIdx = 1;
    local outInfos = {};
    local tStIdx,tEdIdx,value = string.find( str,parttern,stIdx);
    print("formatInfos value=",value)
    while tStIdx do
        stIdx = tEdIdx;
        table.insert( outInfos,{str=value,stIdx=tStIdx,endIdx=tEdIdx,isFace=isFace})
        tStIdx,tEdIdx,value = string.find( str,parttern,stIdx);
    end
    return outInfos;
end

function PrintTabStr(tab)
    local str = "";
    if type(tab)=="table" then
        for key, value in pairs(tab) do
            --print("PrintTabStr value",value,"key",key)
            if type(value)=="table" then
                str = str..key.."=-="..PrintTabStr(value);
            else
                str = str..key.."="..tostring(value);
            end
            str = str.."\n";
        end
    else
        str = tostring(tab);
    end
    return str;
end

function formatText()
    
end

partternFace = "(□%d+□)"

parttern = "(<color=#[%a%d]+>.-</color>)"

faceInfos = formatInfos(orgStr,partternFace,true)
colorInfos = formatInfos(orgStr,parttern,false)


print("faceInfos=",PrintTabStr(faceInfos))
print("colorInfos=",PrintTabStr(colorInfos))

--<color=#00000000>一一一</color>恭喜<color=#144db6>赤壁戴荃</color>的贵族等级达到VIP<color=#313D4F>5</color>，获得多项专属特权，羡煞旁人！
--安定依白:哈哈□6□多试□7□水电<color=#ff0000>你好1</color>撒<color=#ff0000>你好2</color>地是的
--安定依白:哈哈>>>>>多试>>>>>水电你好1撒你好2地是的

--先把原串的表情替换成 >>>>> 得到新的串,
--新串去掉颜色标签，并记录去颜色标签后的文字的下标

--str = string.gsub( str,partternFace,"<<<<<" );
for i=1,#faceInfos do
    str = string.gsub( str,partternFace,"<<"..i.."<<",1);
end

print("去表情后:",str)
local par = "<color=(#[%a%d]+)>(.-)</color>"
for i=1,#colorInfos do
    local info = colorInfos[i];
    local tStIdx,tEdIdx,color,value = string.find( info.str,par);
    if tStIdx then
        --str = string.gsub( str,info.str,value ,1); --每次只替换一次
        info.newStIdx = tStIdx --在新串中的位置
        info.newEndIdx = tEdIdx --在新串中的位置
        info.newStr = value;
        info.color = color;
    end
end
print("========去颜色后:",str) --安定依白:哈哈>>>>>多试>>>>>水电你好1撒你好1地是的

noTagStr = str;

count = 35;
startColorIdx = #colorInfos
colorOffset = 0;
while count>0 do
    
    local len = utf8len(noTagStr);
    local subNum = 1;
    local lastStr = utf8sub(noTagStr,len,subNum);
    if lastStr=="<" then --表情
        len = len-4;
        subNum = 5;
        lastStr = utf8sub(noTagStr,len,subNum);
        --print("******是表情符号 len=",len,"subNum",subNum,"lastStr",lastStr)
    elseif lastStr==">" then --颜色标签
        break;
    end
    len = len - 1 - colorOffset
    noTagStr = utf8sub(noTagStr,1,len);
    print("++++截取count=",count,"lastStr",lastStr,"noTagStr",noTagStr,"len",len)
    count = count - 1;
end

chatStr = "安定依白:撒大多数非<<1<<<<2<<<<3<<<<4<<<<5<<<<6<<<<7<<<<8<<";
local len = utf8len(chatStr);
local tem = utf8sub(chatStr,len,1);
print("tem=",tem,"find=",string.find( chatStr,"<<",1,true ))

--有表情(玩家发送的)
--有颜色标签(广播等系统消息)
--无表情 无颜色标签(玩家发送的)
orgStr = '安定依白:哈哈□6□多试□7□水电地是的';
local chatStrArr = split(orgStr,partternFace);
local last = table.remove( chatStrArr,#chatStrArr )
local newStr = ""
for i = 1, #chatStrArr do
    newStr = newStr..chatStrArr[i];
end
local isFace = string.find( last,partternFace)~=nil;
local isColor = string.find( last,parttern)~=nil;
if isFace then
    --
end

local i,j,size = string.find( "这是谁<size=2.4>哈哈哈</size>","<size=(.-)>" )
print(i,j,size,string.format( "<size=%s>%s</size>",2.4,"□4□"))

local list = {"a","b","c","d"};
list[0] = 10;
print(next(list),"length=",#list)
for k, v in pairs(list) do
    print("k=",k,"v=",v)
end

local UIFx = {};

function UIFx.New(obj)     
    local s = obj or {}      
    return setmetatable(s, { __index = UIFx })
end

function UIFx:Init()
    self.effMask = nil
end

function UIFx:SetMask(go)
    self.effMask = go;
end



local fx = UIFx.New();

fx:SetMask({});
print(" 11 fx.effMask=",fx.effMask);


UIFx:SetMask(nil);
print(" 22 fx.effMask=",fx.effMask,"=",type(11));

local tabHash = {}


print("hash=",table.maxn(tabHash),"nex=",next(tabHash),"len=",#tabHash)
for k, v in pairs(tabHash) do
    print("k,v=",k,v)
end

local nums = {10,2,5,50,30,40}
table.sort( nums, function ( a,b)
    return a < b
end )
for i, v in ipairs(nums) do
    print("sort k,v=",i,v)
end